<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "cate_attr".
 *
 * @property int $id
 * @property int $cate_id 分类ID
 * @property string $name 属性名称
 * @property int $type 0：输入框,1:单选项,2:多选项，3:文本域
 * @property int $sort 排序
 * @property int $is_must 0:可填,1:必填
 * @property int $addtime 添加时间
 */
class CateAttr extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'cate_attr';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['cate_id', 'name', 'addtime'], 'required'],
            [['cate_id', 'sort', 'addtime'], 'integer'],
            [['name'], 'string', 'max' => 30],
            [['type'], 'string', 'max' => 2],
            [['is_must'], 'string', 'max' => 1],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'cate_id' => '分类ID',
            'name' => '属性名称',
            'type' => '0：输入框,1:单选项,2:多选项，3:文本域',
            'sort' => '排序',
            'is_must' => '0:可填,1:必填',
            'addtime' => '添加时间',
        ];
    }
    
    public static function getAttrlistByCate($cate_id){
        $sql = "select * from cate_attr where cate_id=$cate_id order by sort desc";
        $command = \Yii::$app->db->createCommand($sql);
        return $command->queryAll();
    }
}
